package com.vehicle.service.impl;


import com.vehicle.service.SmsService;
import com.vehicle.util.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SmsServiceImpl implements SmsService {
    @Override
    public boolean send(String mobile, String code) {
        String testUsername = "yayyaya_yayay"; //在短信宝注册的用户名
        String testPassword = "LY990412"; //在短信宝注册的密码
        String testContent = "【校园车辆管理系统】尊敬的用户您好，您的验证码是"+code+"。如非本人操作，请忽略本短信。"; // 注意测试时，也请带上公司简称或网站签名，发送正规内容短信。千万不要发送无意义的内容：例如 测一下、您好。否则可能会收不到

        String httpUrl = "http://api.smsbao.com/sms";

        StringBuffer httpArg = new StringBuffer();
        httpArg.append("u=").append(testUsername).append("&");
        httpArg.append("p=").append(SmsUtil.md5(testPassword)).append("&");
        httpArg.append("m=").append(mobile).append("&");
        httpArg.append("c=").append(SmsUtil.encodeUrlString(testContent, "UTF-8"));
        String result = SmsUtil.request(httpUrl, httpArg.toString());
        System.out.println(result);
        System.out.println("这里来不来码");
        return true;
    }

    @Override
    public boolean sendOver(String user_name,String mobile) {
        String testUsername = "yayyaya_yayay"; //在短信宝注册的用户名
        String testPassword = "LY990412"; //在短信宝注册的密码
        String testContent = "【校园车辆管理系统】亲爱的同学"+user_name+"您好,由于您即将毕业且仍然有车辆停在学校，希望您在7月15号之前取走，否则将交由学校处理。祝您顺利毕业，谢谢。"; // 注意测试时，也请带上公司简称或网站签名，发送正规内容短信。千万不要发送无意义的内容：例如 测一下、您好。否则可能会收不到

        String httpUrl = "http://api.smsbao.com/sms";

        StringBuffer httpArg = new StringBuffer();
        httpArg.append("u=").append(testUsername).append("&");
        httpArg.append("p=").append(SmsUtil.md5(testPassword)).append("&");
        httpArg.append("m=").append(mobile).append("&");
        httpArg.append("c=").append(SmsUtil.encodeUrlString(testContent, "UTF-8"));
        String result = SmsUtil.request(httpUrl, httpArg.toString());
        System.out.println(result);
        System.out.println("这里来不来码");
        return true;
    }
}
